package org.openfdtd.core3d;

import com.sun.j3d.utils.universe.Viewer;

/**
 *
 * @author Dórian C. Langbeck
 */
public class Camera {
    public static final int KEY_VNEAR   = 0;
    public static final int KEY_VFAR    = 1;

    private Viewer viewer;

    private void configure() {
        setValue(KEY_VNEAR, 0.0001);
        setValue(KEY_VFAR,  200);
    }
    
    void attach(Viewer viewer) {
        this.viewer = viewer;
        configure();
    }

    void attach(BasicUniverse bu) {
        bu.camera = this;
        viewer = bu.universe.getViewer();
    }

    public void setValue(int key, double value) {
        switch (key) {
            case KEY_VNEAR:
                viewer.getView().setFrontClipDistance(value);
                break;

            case KEY_VFAR:
                viewer.getView().setBackClipDistance(value);
                break;

            default:
                throw new UnsupportedOperationException("The key is invalid.");
        }
    }

    public double getValue(int key) {
        switch (key) {
            case KEY_VNEAR:
                return viewer.getView().getFrontClipDistance();

            case KEY_VFAR:
                return viewer.getView().getBackClipDistance();

            default:
                throw new IllegalArgumentException("The key is invalid.");
        }
    }
}
